#ifndef GEOMETRY_H
#define GEOMETRY_H

#include <QVector3D>

class Ray {
    public:
        Ray() {};
        Ray(QVector3D &point, QVector3D &vector)
            : m_point(point), m_vector(vector) {
        };
        ~Ray() {};

    public:
        QVector3D m_point;
        QVector3D m_vector;
};

class Sphere {
    public:
        Sphere() = default;
        ~Sphere() = default;

    public:
        QVector3D m_center;
        float m_radius;
};

// 平面
class Plan {
    public:
        Plan() = default;
        ~Plan() = default;

    public:
        // 平面上的点
        QVector3D m_point;
        // 平面的法线
        QVector3D m_normal;
};

float distanceBetween(const QVector3D &point, const Ray &ray);

/** 判断射线(ray）是否和球体(sphere)相交
 *
 */
inline bool intersect(Sphere &sphere, Ray &ray) {
    return distanceBetween(sphere.m_center, ray) < sphere.m_radius;
}

/** 计算射线（ray）在平面（plan）上的交点
 *
 */
QVector3D intersect(Plan &plan, Ray &ray);


#endif // GEOMETRY_H
